package z_stuff;

import com.hp.hpl.jena.query.*;

import config.ConfigManager;

public class TestCounting {
	//final static String serviceEndpoint = "http://localhost:8890/sparql/";
	/**
	 * @param args
	 * @throws InstantiationException 
	 */
	public static void main(String[] args) throws InstantiationException {
		
		//PropertyConfigurator.configure("config/log4j.properties");
		ConfigManager config = new ConfigManager();
		
		String serviceEndpoint = config.getVirtuosoSparqlEndpoint();
		
		String comNameQuery = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> SELECT DISTINCT ?entity WHERE {GRAPH <http://dbpedia.org> {?entity rdf:type <http://dbpedia.org/ontology/MeanOfTransportation>} GRAPH <http://aifb.kit.edu/semanticsearch/textcorpus> {?article <http://aifb.kit.edu/semanticsearch/properties/hasAnnotation> ?entity.}}";

		Query query = QueryFactory.create(comNameQuery);  
		QueryExecution qe = QueryExecutionFactory.sparqlService(serviceEndpoint,query);

		  
		
		try {
		    ResultSet rs = qe.execSelect();
		    //ResultSetMem rsmem = ResultSetMem();
		    
		    /*int zaehler = 0;
		   		    
		    while(rs.hasNext()){
		    	rs.next();
		    }
		    zaehler = rs.getRowNumber();*/
		    int zaehler = tools.SparqlTools.countResultSet(rs);
		    
		    System.out.println(zaehler);
		    
		    
		    //int numberOfResults = rsrw.size();
		    //System.out.println(numberOfResults);
		    /* do stuff with the results */
		} 
		catch(Exception e) { 
		    System.out.println(e.getMessage());
		}
		finally {
		    qe.close();
		}

	}

}
